from decimal import Decimal
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from pydantic_validation_decorator import NotBlank
from typing import Optional, List
from module_admin.annotation.pydantic_annotation import as_query


class PackagingModel(BaseModel):
    """
    包装费用管理表对应pydantic模型
    """
    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    packaging_id: Optional[int] = Field(default=None, description='包装方式记录id')
    materials_cost: Optional[Decimal] = Field(default=0, description='包材费')
    chilling_fee: Optional[Decimal] = Field(default=0, description='人工及打冷费')
    product_id: Optional[int] = Field(default=None, description='商品Id')
    product_name: Optional[str] = Field(default=None, description='商品名称')
    product_weight: Optional[Decimal] = Field(default=0, description='商品重量（斤）')
    year: Optional[int] = Field(default=None, description='数据年份')
    as_id: Optional[int] = Field(default=None, description="账套Id")
    create_by: Optional[str] = Field(default=None, description='创建人')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_by: Optional[str] = Field(default=None, description='更新人')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')
    del_status: Optional[int] = Field(default=0, description='删除状态')

    @NotBlank(field_name='materials_cost', message='包材费不能为空')
    def get_materials_cost(self):
        return self.materials_cost

    @NotBlank(field_name='chilling_fee', message='人工及打冷费不能为空')
    def get_chilling_fee(self):
        return self.chilling_fee



    @NotBlank(field_name='year', message='数据年份不能为空')
    def get_year(self):
        return self.year


    def validate_fields(self):
        self.get_materials_cost()
        self.get_chilling_fee()
        self.get_year()


class PackagingAddModel(PackagingModel):
    product_ids: Optional[List[int]] = Field(default=None, description='商品Ids')

    @NotBlank(field_name='product_ids', message='商品Ids不能为空')
    def get_product_ids(self):
        return self.product_ids

    def validate_fields(self):
        self.get_product_ids()

class PackagingQueryModel(PackagingModel):
    """
    包装费用管理不分页查询模型
    """
    pass


@as_query
class PackagingPageQueryModel(PackagingQueryModel):
    """
    包装费用管理分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')


class DeletePackagingModel(BaseModel):
    """
    删除包装费用管理模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    packaging_ids: str = Field(description='需要删除的包装方式记录id')
